//
//  ResourcesDetailsViewController.m
//  Bees
//
//  Created by NowYouCanSee on 2019/1/18.
//  Copyright © 2019 xiaohan. All rights reserved.
//

#import "ResourcesDetailsViewController.h"
#import "UIColor+GradualChanging.h"
#import "KKPaddingLabel.h"
#import "PasswordStrengthIndicatorView.h"
#import "XHomeSegementView.h"
#import "WZSwitch.h"
#import "LeaseListViewController.h"
#import "EOSService.h"
#import "MemoryTradingViewController.h"
#import "FoundServer.h"
#import "WeChatActionSheet.h"
#import "ScatterDappManager.h"
#import "LxHeader.h"
@interface ResourcesTopSubView : UIView
@property (nonatomic,strong) KKPaddingLabel*topLab;
@property (nonatomic,strong) UIView*contentView;
@property (nonatomic,strong) UILabel*titleLab;
@property (nonatomic,strong) UILabel*myLab;
@property (nonatomic,strong) UILabel*otherLab;
@property (nonatomic,strong) UILabel*subTitleLab;
@property (nonatomic,strong) UILabel*subValueLab;
@property (nonatomic,strong) UIButton*rightBtn;
@property (nonatomic,strong) PasswordStrengthIndicatorView*progressView;
@end
@implementation ResourcesTopSubView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    self.contentView = [UIView new];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.contentView];
    self.contentView.layer.cornerRadius = AdaptedWidth(10);
    
    self.topLab = [KKPaddingLabel new];
    ViewBorderRadius(self.topLab, AdaptedWidth(15), 1, UIColor.whiteColor);
    self.topLab.backgroundColor = UIColorHex(#FCD839);
    self.topLab.textColor = UIColor.whiteColor;
    self.topLab.font = FONT(@"MicrosoftYaHei", 15);
    self.topLab.left_padding = 10;
    self.topLab.right_padding = 10;
    [self addSubview:self.topLab];
    
    self.titleLab = [UILabel new];
    self.titleLab.textColor = UIColorHex(#333333);
    self.titleLab.font = kDefaultRegularFont(12);
    [self.contentView addSubview:self.titleLab];

    self.progressView = [PasswordStrengthIndicatorView new];
    self.progressView.backgroundColor = UIColorHex(#F7F7F7);
    [self.contentView addSubview:self.progressView];
    self.progressView.cornerRadius =AdaptedWidth(10);
    self.progressView.tintColor = UIColorHex(#FCD839);
    
    self.subTitleLab = [UILabel new];
    self.subTitleLab.textColor = UIColor.blackColor;
    self.subTitleLab.font = kBoldFont(15);
    self.subTitleLab.text = XLocalized(@"抵押");
    [self.contentView addSubview:self.subTitleLab];
    
    self.subValueLab = [UILabel new];
    self.subValueLab.textColor = UIColor.blackColor;
    self.subValueLab.font = kDefaultRegularFont(15);
    [self.contentView addSubview:self.subValueLab];
    
    self.myLab = [UILabel new];
    self.myLab.textColor = UIColorHex(#000000);
    self.myLab.font = kDefaultRegularFont(14);
    [self.contentView addSubview:self.myLab];
    
    self.otherLab = [UILabel new];
    self.otherLab.textColor = UIColorHex(#000000);
    self.otherLab.font = kDefaultRegularFont(14);
    [self.contentView addSubview:self.otherLab];
    
    self.rightBtn = [UIButton new];
    [self.rightBtn setTitle:XLocalized(@"租赁") forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:UIColorHex(#FFCC03) forState:UIControlStateNormal];
    self.rightBtn.titleLabel.font = kDefaultFont(12);
    [self.contentView addSubview:self.rightBtn];
}
- (void)layoutSubviews{
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(AdaptedWidth(15));
    }];
    [self.topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(AdaptedWidth(23));
        make.height.mas_equalTo(AdaptedWidth(30));
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(AdaptedWidth(35));
        make.left.mas_equalTo(AdaptedWidth(20));
    }];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab.mas_left);
        make.top.equalTo(self.titleLab.mas_bottom);
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.height.mas_equalTo(AdaptedWidth(20));
    }];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.progressView.mas_bottom).offset(AdaptedWidth(13));
        make.left.equalTo(self.titleLab.mas_left);
    }];
    [self.subValueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab.mas_left);
        make.bottom.mas_equalTo(AdaptedWidth(-13));
    }];
    [self.myLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.left.equalTo(self.subTitleLab.mas_right).offset(20);
        make.centerY.equalTo(self.subTitleLab.mas_centerY);
    }];
    [self.otherLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.centerY.equalTo(self.subValueLab.mas_centerY);
        make.left.equalTo(self.subValueLab.mas_right).offset(20);
    }];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-8));
        make.top.mas_equalTo(AdaptedWidth(3));
        make.size.mas_equalTo(CGSizeMake(40, 30));
    }];
}
@end



@interface ResourceMiddleSubView : UIView
@property (nonatomic,strong) KKPaddingLabel*topLab;
@property (nonatomic,strong) UIView*contentView;
@property (nonatomic,strong) UILabel*titleLab;
@property (nonatomic,strong) UILabel*subTitleLab;
@property (nonatomic,strong) PasswordStrengthIndicatorView*progressView;
@property (nonatomic,strong) UIButton*rightBtn;

@end
@implementation ResourceMiddleSubView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    self.contentView = [UIView new];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.contentView];
    self.contentView.layer.cornerRadius = AdaptedWidth(10);
    
    self.topLab = [KKPaddingLabel new];
    ViewBorderRadius(self.topLab, AdaptedWidth(15), 1, UIColor.whiteColor);
    self.topLab.backgroundColor = UIColorHex(#FCD839);
    self.topLab.textColor = UIColor.whiteColor;
    self.topLab.font = FONT(@"MicrosoftYaHei", 15);
    self.topLab.left_padding = 10;
    self.topLab.right_padding = 10;
    self.topLab.text = XLocalized(@"内存");
    [self addSubview:self.topLab];
    
    self.titleLab = [UILabel new];
    self.titleLab.textColor = UIColorHex(#333333);
    self.titleLab.font = kDefaultRegularFont(12);
    [self.contentView addSubview:self.titleLab];
    
    self.progressView = [PasswordStrengthIndicatorView new];
    self.progressView.backgroundColor = UIColorHex(#F7F7F7);
    [self.contentView addSubview:self.progressView];
    self.progressView.cornerRadius =AdaptedWidth(10);
    self.progressView.tintColor = UIColorHex(#FCD839);
    
    self.subTitleLab = [UILabel new];
    self.subTitleLab.textColor = UIColor.blackColor;
    self.subTitleLab.font = kDefaultFont(15);
    [self.contentView addSubview:self.subTitleLab];
    
    self.rightBtn = [UIButton new];
    [self.rightBtn setTitle:XLocalized(@"内存交易") forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:UIColorHex(#FFCC03) forState:UIControlStateNormal];
    self.rightBtn.titleLabel.font = kDefaultFont(12);
    [self.contentView addSubview:self.rightBtn];
}
- (void)layoutSubviews{
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(AdaptedWidth(15));
    }];
    [self.topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(AdaptedWidth(23));
        make.height.mas_equalTo(AdaptedWidth(30));
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(AdaptedWidth(35));
        make.left.mas_equalTo(AdaptedWidth(20));
    }];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab.mas_left);
        make.top.equalTo(self.titleLab.mas_bottom);
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.height.mas_equalTo(AdaptedWidth(20));
    }];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.progressView.mas_top);
        make.right.equalTo(self.contentView.mas_right).offset(AdaptedWidth(-20));
    }];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-8));
        make.top.mas_equalTo(AdaptedWidth(3));
        make.size.mas_equalTo(CGSizeMake(50, 30));
    }];
}
@end


@interface ResourceBottomSubView : UIView
@property (nonatomic,strong) UILabel*topLab;
@property (nonatomic,strong) UIView*contentView;
@property (nonatomic,strong) UILabel*titleLab;
@property (nonatomic,strong) UILabel*subTitleLab;
@property (nonatomic,strong) UILabel*downTimeLab;
@property (nonatomic,strong) UILabel*notLab;
@property (nonatomic,strong) UIButton*listBtn;
@property (nonatomic,strong) UIButton*backBtn;
@property (nonatomic,copy) void(^LeaseBlock)(void);
@property (nonatomic,copy) void(^BackBlock)(void);
@end
@implementation ResourceBottomSubView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    self.contentView = [UIView new];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.contentView];
    self.contentView.layer.cornerRadius = AdaptedWidth(10);
    
    self.topLab = [UILabel new];
    self.topLab.textColor = UIColorHex(#FFCC03);
    self.topLab.font = FONT(@"MicrosoftYaHei", 15);
    self.topLab.text = XLocalized(@"赎回中...");
    [self addSubview:self.topLab];
    
    self.titleLab = [UILabel new];
    self.titleLab.textColor = UIColorHex(#333333);
    self.titleLab.font = kDefaultFont(15);
    [self.contentView addSubview:self.titleLab];
    
    self.subTitleLab = [UILabel new];
    self.subTitleLab.textColor = UIColorHex(#333333);
    self.subTitleLab.font = kDefaultFont(15);
    [self.contentView addSubview:self.subTitleLab];
    
    self.downTimeLab = [UILabel new];
    self.downTimeLab.textColor = UIColorHex(#333333);
    self.downTimeLab.font = kDefaultFont(15);
    [self.contentView addSubview:self.downTimeLab];
    
    self.listBtn = [UIButton new];
    [self.listBtn setTitle:XLocalized(@"租借列表") forState:UIControlStateNormal];
    [self.listBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    self.listBtn.titleLabel.font = kDefaultFont(12);
    [self.listBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#FFCC03)] forState:UIControlStateNormal];
    ViewRadius(self.listBtn, AdaptedWidth(13));
    [self.contentView addSubview:self.listBtn];
    kWeakSelf(self);
    [self.listBtn addTapBlock:^(UIButton * _Nonnull btn) {
        !weakself.LeaseBlock?:weakself.LeaseBlock();
    }];
    
    self.backBtn = [UIButton new];
    [self.backBtn setTitle:XLocalized(@"立即取回") forState:UIControlStateNormal];
    [self.backBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    self.backBtn.titleLabel.font = kDefaultFont(12);
    [self.backBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#FFCC03)] forState:UIControlStateNormal];
    ViewRadius(self.backBtn, AdaptedWidth(13));
    [self.contentView addSubview:self.backBtn];
    [self.backBtn addTapBlock:^(UIButton * _Nonnull btn) {
        !weakself.BackBlock?:weakself.BackBlock();
    }];
    self.backBtn.hidden = YES;
    self.notLab = [UILabel new];
    self.notLab.hidden = YES;
    self.notLab.textColor = UIColorHex(#B5B5B5);
    self.notLab.font = kDefaultFont(15);
    self.notLab.text = XLocalized(@"暂无赎回资源");
    [self.contentView addSubview:self.notLab];
}
- (void)layoutSubviews{
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(0);
    }];
    [self.topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(AdaptedWidth(15));
        make.left.mas_equalTo(AdaptedWidth(19));
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topLab.mas_bottom).offset(AdaptedWidth(15));
        make.left.mas_equalTo(AdaptedWidth(20));
    }];
    [self.downTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLab.mas_centerY);
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.left.equalTo(self.titleLab.mas_right).offset(20);
    }];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(AdaptedWidth(-13));
        make.left.equalTo(self.titleLab.mas_left);
    }];
    [self.listBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topLab.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(80), AdaptedWidth(26)));
        make.right.mas_equalTo(AdaptedWidth(-20));
    }];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.listBtn);
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(80), AdaptedWidth(26)));
        make.bottom.mas_equalTo(AdaptedWidth(-20));
    }];
    
    [self.notLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(AdaptedWidth(-30));
    }];
}
@end


@interface ResourceBottomChooseSubView : UIView <UITextFieldDelegate>
@property (nonatomic,strong) XHomeSegementView *segementView;
@property (nonatomic,strong) UILabel*topLab;
@property (nonatomic,strong) UILabel*cpuLab;
@property (nonatomic,strong) UILabel*netLab;
@property (nonatomic,strong) UITextField*cpuTF;
@property (nonatomic,strong) UITextField*netTF;
@property (nonatomic,strong) UILabel*titleLab;
@property (nonatomic,strong) UILabel*subTitleLab;
@property (nonatomic,strong) UILabel*downTimeLab;
@property (nonatomic,strong) UIButton*listBtn;
@property (nonatomic,strong) UIView*line1;
@property (nonatomic,strong) UIView*line2;
@property (nonatomic,strong) UILabel*bottomLab;
@property (nonatomic,strong) UIView*line3;
@property (nonatomic,strong) WZSwitch*switchView;
@property (nonatomic,strong) UIView*bottomView;
@property (nonatomic,strong) UITextField*userTF;
@property (nonatomic,strong) UIButton*leftBtn;
@property (nonatomic,strong) UIButton*rightBtn;
@property (nonatomic,strong) XThemeFlatButton*bottomBtn;
@property (nonatomic,strong) EOSAccountInfo *accountResult;

///抵押资源 或者赎回资源
@property (nonatomic,copy) void(^SureBlock)(void);
///是否租借
@property(nonatomic,assign) BOOL isMortgage;
///抵押还是赎回
@property(nonatomic,assign) ResourcesDetailsChooseType type;
///自己还是他人
@property(nonatomic,assign) BOOL isSelf;

@property(nonatomic,assign) BOOL isShowMsg;

@end
@implementation ResourceBottomChooseSubView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
- (void)setAccountResult:(EOSAccountInfo *)accountResult
{
    _accountResult = accountResult;
    self.topLab.text = [NSString stringWithFormat:@"%@：%@",XLocalized(@"余额"),accountResult.core_liquid_balance];
}
- (void)setIsMortgage:(BOOL)isMortgage{
    _isMortgage = isMortgage;
    self.leftBtn.selected = isMortgage;
    self.rightBtn.selected = !isMortgage;
}
- (void)setupUI{
    kWeakSelf(self);
    self.backgroundColor = UIColor.whiteColor;
    self.segementView = [[XHomeSegementView alloc]initWithFrame:CGRectMake((kScreenWidth-AdaptedWidth(170))*.5,0,AdaptedWidth(170), KHomeSegementHeight)];
    self.segementView.fixedWidth = AdaptedWidth(85);
    self.segementView.titles = @[XLocalized(@"抵押资源"),XLocalized(@"赎回资源")];
    self.segementView.resultBlock = ^(NSInteger index) {
        if (index==0) {
            [weakself.bottomBtn setTitle:XLocalized(@"抵押") forState:UIControlStateNormal];
            weakself.userTF.placeholder = XLocalized(@"接收者账号");
            weakself.leftBtn.hidden = NO;
            weakself.rightBtn.hidden = NO;
            weakself.type = ResourcesDetailsChooseTypeMortgage;
            weakself.cpuTF.placeholder = XLocalized(@"请输入EOS数量");
            weakself.netTF.placeholder = XLocalized(@"请输入EOS数量");
        }else{
            [weakself.bottomBtn setTitle:XLocalized(@"赎回") forState:UIControlStateNormal];
            weakself.userTF.placeholder = XLocalized(@"取回账号");
            weakself.leftBtn.hidden = YES;
            weakself.rightBtn.hidden = YES;
            weakself.type = ResourcesDetailsChooseTypeDemption;
            weakself.cpuTF.placeholder = [NSString stringWithFormat:@"%@%@",XLocalized(@"可赎回"),IsNilOrNull(weakself.accountResult.self_delegated_bandwidth.cpu_weight)?@"0 EOS":weakself.accountResult.self_delegated_bandwidth.cpu_weight];
            weakself.netTF.placeholder = [NSString stringWithFormat:@"%@%@",XLocalized(@"可赎回"),IsNilOrNull(weakself.accountResult.self_delegated_bandwidth.net_weight)?@"0 EOS":weakself.accountResult.self_delegated_bandwidth.net_weight];
        }
    };
    [self addSubview:self.segementView];
    
    self.topLab = [UILabel new];
    self.topLab.textColor = UIColorHex(#999999);
    self.topLab.font = kDefaultFont(12);
    [self addSubview:self.topLab];
    
    self.cpuLab = [UILabel new];
    self.cpuLab.textColor = UIColorHex(#000000);
    self.cpuLab.font = kDefaultFont(15);
    [self addSubview:self.cpuLab];
    
    self.cpuTF = [UITextField new];
    self.cpuTF.font = kDefaultFont(12);
    self.cpuLab.text = @"CPU";
    self.cpuTF.textAlignment = NSTextAlignmentRight;
    self.cpuTF.keyboardType = UIKeyboardTypeDecimalPad;
    self.cpuTF.delegate = self;
    [self addSubview:self.cpuTF];
    
    self.line1 = [UIView new];
    self.line1.backgroundColor = kLineColor;
    [self addSubview:self.line1];
    
    self.netLab = [UILabel new];
    self.netLab.textColor = UIColorHex(#000000);
    self.netLab.text = @"NET";
    self.netLab.font = kDefaultFont(15);
    [self addSubview:self.netLab];
    
    self.netTF = [UITextField new];
    self.netTF.font = kDefaultFont(12);
    self.netTF.textAlignment = NSTextAlignmentRight;
    self.netTF.keyboardType = UIKeyboardTypeDecimalPad;
    self.netTF.delegate = self;
    [self addSubview:self.netTF];
    
    self.line2 = [UIView new];
    self.line2.backgroundColor = kLineColor;
    [self addSubview:self.line2];
    
    self.bottomLab = [UILabel new];
    self.bottomLab.textColor = UIColorHex(000000);
    self.bottomLab.font = kDefaultFont(15);
    self.bottomLab.text = XLocalized(@"接收账号");
    [self addSubview:self.bottomLab];
    
    self.line3 = [UIView new];
    self.line3.backgroundColor = kLineColor;
    [self addSubview:self.line3];
    
    self.switchView = [WZSwitch new];
    self.switchView.backgroundColor = UIColorHex(#F7F7F7);
    [self addSubview:self.switchView];
    [self.switchView setLeftString:XLocalized(@"自己")];
    [self.switchView setRightString:XLocalized(@"他人")];
    [self.switchView setSelectColor:UIColorHex(#FFFFFF)];
    [self.switchView setUnselectColor:UIColorHex(333333)];
    [self.switchView setMoveViewColor:UIColorHex(#FFCC03)];
    [self.switchView setTextFont:kBoldFont(12)];
    self.switchView.block = ^(BOOL state) {
        if (state) {
            weakself.isSelf = NO;
            [UIView animateWithDuration:1.35f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                weakself.bottomView.hidden=NO;
                [weakself.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.height.mas_equalTo(AdaptedWidth(45));
                }];
            } completion:^(BOOL finished) {
            }];
        }else{
            weakself.isSelf = YES;
            weakself.isMortgage = YES;
            [UIView animateWithDuration:1.35f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                weakself.bottomView.hidden=YES;
                [weakself.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.height.mas_equalTo(.1);
                }];
            } completion:^(BOOL finished) {
            }];
        }
    };

    self.bottomBtn  = [XThemeFlatButton button];
    [self.bottomBtn setTitle:XLocalized(@"抵押") forState:UIControlStateNormal];
    [self addSubview:self.bottomBtn];
    [self.bottomBtn addTapBlock:^(UIButton * _Nonnull btn) {
        if ([weakself.cpuTF.text floatValue]<=0 && [weakself.netTF.text floatValue]<=0) {
            [[kAppDelegate getCurrentVC].view makeToast:XLocalized(@"无效的数量！") duration:2.0f position:CSToastPositionBottom];
            return;
        }
        if (!weakself.isSelf && ![RegularExp validateEosAccountName:weakself.userTF.text]) {
            [[kAppDelegate getCurrentVC].view makeToast:XLocalized(@"无效的账号！") duration:2.0f position:CSToastPositionBottom];
            return;
        }
        if (weakself.type == ResourcesDetailsChooseTypeMortgage) {
            if (SNCompare(SNAdd(weakself.cpuTF.text.length?weakself.cpuTF.text:@"0", weakself.netTF.text.length?weakself.netTF.text:@"0"), [weakself.accountResult.core_liquid_balance getDigital])==NSOrderedDescending) {
                [[kAppDelegate getCurrentVC].view makeToast:XLocalized(@"输入数量超过可用余额！") duration:2.0f position:CSToastPositionBottom];
                return;
            }else{
                DLog(@"数量OK");
            }
        }else{
            if (SNCompare(weakself.cpuTF.text.length?weakself.cpuTF.text:@"0",[weakself.accountResult.self_delegated_bandwidth.cpu_weight getDigital])==NSOrderedDescending) {
                [[kAppDelegate getCurrentVC].view makeToast:XLocalized(@"输入数量超过可赎回CPU数量！") duration:2.0f position:CSToastPositionBottom];
                return;
            }
            if (SNCompare(weakself.netTF.text.length?weakself.netTF.text:@"0",[weakself.accountResult.self_delegated_bandwidth.net_weight getDigital])==NSOrderedDescending) {
                [[kAppDelegate getCurrentVC].view makeToast:XLocalized(@"输入数量超过可赎回NET数量！") duration:2.0f position:CSToastPositionBottom];
                return;
            }
        }
        
        [XAlertTool alertTitle:[NSString stringWithFormat:@"%@%@？",XLocalized(@"确认"),weakself.bottomBtn.titleLabel.text] message:nil cancelAction:^{
        } sureAction:^{
            !weakself.SureBlock?:weakself.SureBlock();
        }];
    }];
    
    
    self.bottomView = [UIView new];
    [self addSubview:self.bottomView];
    self.bottomView.hidden=YES;
    
    self.userTF = [UITextField new];
    UIView*leftV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, AdaptedWidth(37), AdaptedWidth(37))];
    UIImageView*imageV = [UIImageView new];
    imageV.image = IMAGE_NAMED(@"gray_people");
    [leftV addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(21), AdaptedWidth(19)));
    }];
    if(@available(iOS 13.0, *)) {
//        [self.userTF addSubview:leftV];
//        [leftV mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(0);
//            make.centerY.mas_equalTo(0);
//        }];
    }else{
        self.userTF.leftView = leftV;
        self.userTF.leftViewMode = UITextFieldViewModeAlways;
    }
  
    self.userTF.font = kDefaultFont(13);
    self.userTF.placeholder = XLocalized(@"接受者账号");
    self.userTF.backgroundColor=UIColorHex(#F7F7F7);
    self.userTF.layer.cornerRadius = AdaptedWidth(10);
    self.userTF.delegate = self;
    self.userTF.returnKeyType=UIReturnKeyDone;
    [self.bottomView addSubview:self.userTF];
    
    self.leftBtn = [UIButton new];
    self.leftBtn.titleLabel.font = kBoldFont(13);
    [self.leftBtn setTitle:XLocalized(@"租借") forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:UIColorHex(#333333) forState:UIControlStateNormal];
    [self.leftBtn setImage:IMAGE_NAMED(@"yuan_unselect") forState:UIControlStateNormal];
    [self.leftBtn setImage:IMAGE_NAMED(@"yuan_select") forState:UIControlStateSelected];
    [self.bottomView addSubview:self.leftBtn];
    self.rightBtn = [UIButton new];
    self.rightBtn.titleLabel.font = kBoldFont(13);
    [self.rightBtn setTitle:XLocalized(@"过户") forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:UIColorHex(#333333) forState:UIControlStateNormal];
    [self.rightBtn setImage:IMAGE_NAMED(@"yuan_unselect") forState:UIControlStateNormal];
    [self.rightBtn setImage:IMAGE_NAMED(@"yuan_select") forState:UIControlStateSelected];
    [self.bottomView addSubview:self.rightBtn];
    
    [self.leftBtn addTapBlock:^(UIButton * _Nonnull btn) {
        weakself.isMortgage = YES;
    }];
    [self.rightBtn addTapBlock:^(UIButton * _Nonnull btn) {
        weakself.isMortgage = NO;
        if (!weakself.isShowMsg) {
            weakself.isShowMsg = YES;
            [XAlertTool alertTitle:@"选择过户后，抵押给其他账号的资源将不可收回，请谨慎操作！" message:nil
                      cancelAction:nil sureAction:^{}];
        }
    }];
    ///默认为租借
    self.leftBtn.selected = YES;
    self.isMortgage = YES;
    ///默认自己
    self.isSelf = YES;
    self.cpuTF.placeholder = XLocalized(@"请输入EOS数量");
    self.netTF.placeholder = XLocalized(@"请输入EOS数量");
    self.topLab.text = [NSString stringWithFormat:@"%@：~",XLocalized(@"余额")];
}

- (void)layoutSubviews{
    [self.topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.segementView.mas_bottom).offset(AdaptedWidth(18));
        make.left.mas_equalTo(AdaptedWidth(20));
    }];
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topLab.mas_bottom).offset(AdaptedWidth(50));
        make.left.mas_equalTo(AdaptedWidth(20));
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(CGFloatFromPixel(1));
    }];
    [self.cpuTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.left.equalTo(self.cpuLab.mas_right).offset(AdaptedWidth(80));
        make.height.mas_equalTo(AdaptedWidth(45));
        make.bottom.equalTo(self.line1.mas_top);
    }];
    [self.cpuLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(AdaptedWidth(20));
        make.centerY.equalTo(self.cpuTF.mas_centerY);
    }];
 
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line1.mas_bottom).offset(AdaptedWidth(45));
        make.left.mas_equalTo(AdaptedWidth(20));
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(CGFloatFromPixel(1));
    }];
    [self.netTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.left.equalTo(self.netLab.mas_right).offset(AdaptedWidth(80));
        make.height.mas_equalTo(AdaptedWidth(45));
        make.bottom.equalTo(self.line2.mas_top);
    }];
    [self.netLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(AdaptedWidth(20));
        make.centerY.equalTo(self.netTF.mas_centerY);
    }];
   
    [self.line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line2.mas_bottom).offset(AdaptedWidth(45));
        make.left.mas_equalTo(AdaptedWidth(20));
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(CGFloatFromPixel(1));
    }];
    
    [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.top.equalTo(self.line2.mas_bottom).offset(AdaptedWidth(9));
        make.bottom.equalTo(self.line3.mas_top).offset(AdaptedWidth(-9));
        make.width.mas_equalTo(90);
    }];
    
    [self.bottomLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.switchView.mas_centerY);
        make.left.mas_equalTo(AdaptedWidth(20));
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line3.mas_bottom);
        make.left.mas_equalTo(AdaptedWidth(20));
        make.right.mas_equalTo(AdaptedWidth(-20));
    }];
    
    [self.bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView.mas_bottom).offset(AdaptedWidth(25));
        make.left.mas_equalTo(AdaptedWidth(20));
        make.right.mas_equalTo(AdaptedWidth(-20));
        make.height.mas_equalTo(AdaptedWidth(40));
        make.bottom.mas_equalTo(-50);
    }];
 
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.height.equalTo(self.userTF.mas_height);
        make.centerY.equalTo(self.userTF.mas_centerY);
        make.width.mas_equalTo(AdaptedWidth(50));
    }];
    [self.rightBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:AdaptedWidth(8)];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.rightBtn.mas_left).offset(AdaptedWidth(-12));
        make.height.equalTo(self.rightBtn.mas_height);
        make.width.equalTo(self.rightBtn.mas_width);
        make.centerY.equalTo(self.rightBtn.mas_centerY);
    }];
    [self.leftBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:AdaptedWidth(8)];

    [self.userTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(AdaptedWidth(37));
        make.right.equalTo(self.leftBtn.mas_left).offset(-13);
    }];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == self.userTF) {
        return YES;
    }
    return [RegularExp controllTheAmountfNumberWithString:textField shouldChangeCharactersInRange:range replacementString:string maxDecimalLength:kSymbolLength_EOS];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
@end

@interface ResourcesDetailsViewController ()
@property (nonatomic,strong) ResourcesTopSubView *firstView;
@property (nonatomic,strong) ResourcesTopSubView *secondView;
@property (nonatomic,strong) ResourceMiddleSubView *middleView;
@property (nonatomic,strong) ResourceBottomSubView *bottomView;
@property (nonatomic,strong) ResourceBottomChooseSubView *chooseView;
@property (nonatomic,strong) EOSService *eosService;
@property (nonatomic,strong) FoundServer *foundServer;
@property (nonatomic,assign) ResourcesDetailsChooseType chooseType;
@end

@implementation ResourcesDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self getaccountInfo];
}

- (void)getaccountInfo{
    [self.eosService getAccountInfoComplete:^(BOOL success, NSString * _Nonnull errorMsg) {
        [self.scrollContentView.mj_header endRefreshing];
        if (success) {
            EOSAccountDelegatedBandwidth*selfdelegate = self.eosService.accountResult.self_delegated_bandwidth;
            EOSAccountTotalResources*total_resources = self.eosService.accountResult.total_resources;
            EOSAccountLimit*cpu_limit = self.eosService.accountResult.cpu_limit;
            EOSAccountLimit*net_limit = self.eosService.accountResult.net_limit;
            self.chooseView.accountResult = self.eosService.accountResult;
//            if (!IsNilOrNull(selfdelegate) && !IsNilOrNull(total_resources) && !IsNilOrNull(cpu_limit) && !IsNilOrNull(net_limit)) {
                NSDecimalNumber*cpu_other = handlerDecimalNumber(SNSub([total_resources.cpu_weight getDigital]?:@"0", [selfdelegate.cpu_weight getDigital]?:@"0"), NSRoundPlain, kSymbolLength_EOS);
                self.firstView.myLab.text = [NSString stringWithFormat:@"%@：%@",XLocalized(@"自己"),IsNilOrNull(selfdelegate.cpu_weight)?@"0 EOS":selfdelegate.cpu_weight];
                self.firstView.otherLab.text = [NSString stringWithFormat:@"%@：%@ %@",XLocalized(@"他人"),[NSString stringWithFormat:@"%.*lf",kSymbolLength_EOS,cpu_other.doubleValue],[total_resources.cpu_weight getUnit]];
                self.firstView.subValueLab.text = total_resources.cpu_weight;
                NSString*used =  handlerDecimalNumber(SNDiv(cpu_limit.used,@1000),NSRoundPlain, 2).stringValue;
                NSString*available =  handlerDecimalNumber(SNDiv(cpu_limit.max,@1000),NSRoundPlain, 2).stringValue;
                self.firstView.titleLab.text = [NSString stringWithFormat:@"CPU%@: %@ ms / %@ ms",XLocalized(@"已用"),used,available];
                [self.firstView.progressView animateIndicatorViewToProgress:SNDiv(cpu_limit.used, cpu_limit.max).floatValue];
                
            NSDecimalNumber*net_other = handlerDecimalNumber(SNSub([total_resources.net_weight getDigital]?:@"0", [selfdelegate.net_weight getDigital]?:@"0"), NSRoundPlain, kSymbolLength_EOS);
                self.secondView.myLab.text = [NSString stringWithFormat:@"%@：%@",XLocalized(@"自己"),IsNilOrNull(selfdelegate.net_weight)?@"0 EOS":selfdelegate.net_weight];
                self.secondView.otherLab.text = [NSString stringWithFormat:@"%@：%@ %@",XLocalized(@"他人"),[NSString stringWithFormat:@"% .*lf",kSymbolLength_EOS,net_other.doubleValue],[total_resources.net_weight getUnit]];
                self.secondView.subValueLab.text = total_resources.net_weight;
                NSString*net_used =  handlerDecimalNumber(SNDiv(net_limit.used,@1024),NSRoundPlain, 2).stringValue;
                NSString*net_available =  handlerDecimalNumber(SNDiv(net_limit.max,@1024),NSRoundPlain, 2).stringValue;
                self.secondView.titleLab.text = [NSString stringWithFormat:@"NET%@: %@ KB / %@ KB",XLocalized(@"已用"),net_used,net_available];
                [self.secondView.progressView animateIndicatorViewToProgress:SNDiv(net_limit.used, net_limit.max).floatValue];
//            }else{
//                [self.firstView.progressView animateIndicatorViewToProgress:0];
//                self.firstView.myLab.text =  [NSString stringWithFormat:@"%@：~",XLocalized(@"自己")];;
//                self.firstView.otherLab.text = [NSString stringWithFormat:@"%@：~",XLocalized(@"他人")];;
//                self.firstView.subValueLab.text = @"~";
//                [self.secondView.progressView animateIndicatorViewToProgress:0];
//                self.secondView.myLab.text = [NSString stringWithFormat:@"%@：~",XLocalized(@"自己")];;
//                self.secondView.otherLab.text =  [NSString stringWithFormat:@"%@：~",XLocalized(@"他人")];;
//                self.secondView.subValueLab.text = @"~";
//            }
//            if (!IsNilOrNull(self.eosService.accountResult.ram_quota) && !IsNilOrNull(self.eosService.accountResult.ram_usage)) {
                NSString*ram_quota =  handlerDecimalNumber(SNDiv(self.eosService.accountResult.ram_quota,@1024),NSRoundPlain, 2).stringValue;
                NSString*ram_usage =  handlerDecimalNumber(SNDiv(self.eosService.accountResult.ram_usage,@1024),NSRoundPlain, 2).stringValue;
                self.middleView.titleLab.text =  [NSString stringWithFormat:@"%@%@: %@ KB / %@ KB",XLocalized(@"内存"),XLocalized(@"已用"),ram_usage,ram_quota];
                self.middleView.subTitleLab.text = [NSString stringWithFormat:@"%@ KB",ram_quota];
                [self.middleView.progressView animateIndicatorViewToProgress:SNDiv(self.eosService.accountResult.ram_usage, self.eosService.accountResult.ram_quota).floatValue];
//            }else{
//                self.middleView.titleLab.text =  [NSString stringWithFormat:@"%@%@: %@ KB / %@ KB",XLocalized(@"内存"),XLocalized(@"已用"),@"~",@"~"];
//                self.middleView.subTitleLab.text = [NSString stringWithFormat:@"%@ KB",@"~"];
//                [self.middleView.progressView animateIndicatorViewToProgress:0];
//            }
            EOSAccountRefundRequest*refund_request = self.eosService.accountResult.refund_request;
            if (!IsNilOrNull(refund_request)) {
                self.bottomView.notLab.hidden = YES;
                self.bottomView.titleLab.hidden = NO;
                self.bottomView.subTitleLab.hidden = NO;
                self.bottomView.downTimeLab.hidden = NO;
                self.bottomView.titleLab.text = [NSString stringWithFormat:@"%@ %@",XLocalized(@"计算"),refund_request.cpu_amount];
                self.bottomView.subTitleLab.text = [NSString stringWithFormat:@"%@ %@",XLocalized(@"网络"),refund_request.net_amount];
                NSString*request_time = [TimeHelper getDownTime:refund_request.request_time downDays:3];
                if (request_time) {
                    self.bottomView.downTimeLab.text = request_time;
                    self.bottomView.downTimeLab.hidden = NO;
                    self.bottomView.backBtn.hidden = YES;
                }else{
                    self.bottomView.downTimeLab.hidden = YES;
                    self.bottomView.backBtn.hidden = NO;
                }
            }else{
                self.bottomView.notLab.hidden = NO;
                self.bottomView.titleLab.hidden = YES;
                self.bottomView.subTitleLab.hidden = YES;
                self.bottomView.downTimeLab.hidden = YES;
                self.bottomView.backBtn.hidden = YES;
            }
            self.chooseView.topLab.text = [NSString stringWithFormat:@"%@：%@",XLocalized(@"余额"),self.eosService.accountResult.core_liquid_balance];;
        }else{
            [self.view makeToast:errorMsg];
        }
    }];
}

- (void)setupUI{
    self.title = XLocalized(@"资源");
//    self.scrollContentView.bounces = NO;
    self.StatusBarStyle = UIStatusBarStyleLightContent;
    self.leftBackImg = @"white_back";
    self.navBarTintColor = UIColor.whiteColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.scrollContentView.backgroundColor = UIColor.clearColor;
    self.customNavigationBar.backgroundColor = UIColor.clearColor;
    [self.view.layer insertSublayer:[UIColor setGradualChangingFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) fromColor:[kGradientColors firstObject] toColor:[kGradientColors lastObject]] atIndex:0];
    
    self.firstView = [[ResourcesTopSubView alloc]initWithFrame:CGRectZero];;
    [self.contentView addSubview:self.firstView];
    [self.firstView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kNormalSpace);
        make.left.mas_equalTo(kNormalSpace);
        make.top.mas_equalTo(kNormalSpace);
        make.height.mas_equalTo(AdaptedWidth(160));
    }];
    self.secondView = [[ResourcesTopSubView alloc]initWithFrame:CGRectZero];;
    [self.contentView addSubview:self.secondView];
    [self.secondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kNormalSpace);
        make.left.mas_equalTo(kNormalSpace);
        make.top.equalTo(self.firstView.mas_bottom).offset(kNormalSpace);
        make.height.mas_equalTo(AdaptedWidth(160));
    }];
    self.middleView = [ResourceMiddleSubView new];
    [self.contentView addSubview:self.middleView];
    [self.middleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kNormalSpace);
        make.left.mas_equalTo(kNormalSpace);
        make.top.equalTo(self.secondView.mas_bottom).offset(kNormalSpace);
        make.height.mas_equalTo(AdaptedWidth(110));
    }];
    
    self.bottomView = [ResourceBottomSubView new];
    [self.contentView addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kNormalSpace);
        make.left.mas_equalTo(kNormalSpace);
        make.top.equalTo(self.middleView.mas_bottom).offset(AdaptedWidth(30));
        make.height.mas_equalTo(AdaptedWidth(110));
    }];
    kWeakSelf(self);
    self.bottomView.LeaseBlock = ^{
        LeaseListViewController *vc = [LeaseListViewController new];
        vc.wallet = weakself.wallet;
        [weakself.navigationController pushViewController:vc animated:YES];
    };
    
    self.bottomView.BackBlock = ^{
        [WalletTool checkPrivateInputPasswordWith:weakself.wallet complete:^(BOOL result,NSString * _Nonnull privateKey) {
            if (result) {
                weakself.eosService.toUser = weakself.wallet.wallet_name;
                NSString* stake_cpu_quantity = weakself.eosService.accountResult.refund_request.cpu_amount;
                NSString* stake_net_quantity = weakself.eosService.accountResult.refund_request.net_amount;
                weakself.eosService.stake_cpu_quantity = stake_cpu_quantity;
                weakself.eosService.stake_net_quantity = stake_net_quantity;
                weakself.eosService.account = kContractName_EOSIO;
                weakself.eosService.available_keys = @[VALIDATE_STRING(weakself.wallet.wallet_public_key)];
                weakself.eosService.actor = weakself.wallet.wallet_name;
                weakself.eosService.privateKey = privateKey;
                [MBProgressHUD showLoadTitile:@"" ToView:weakself.view];
                weakself.eosService.action = ContractAction_UNDELEGATEBW;
                [weakself.eosService redemptionResourcesComplete:^(BOOL success, NSString * _Nonnull errorMsg) {
                    [MBProgressHUD hideHUDForView:weakself.view];
                    [weakself.view makeToast:errorMsg];
                    if (success) {
                        [weakself getaccountInfo];
                    }
                    weakself.chooseView.cpuTF.text = @"";
                    weakself.chooseView.netTF.text = @"";
                    weakself.chooseView.userTF.text = @"";
                }];
            }
        }];
      
    };
    
    self.chooseView = [ResourceBottomChooseSubView new];
    [self.contentView addSubview:self.chooseView];
    [self.chooseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView.mas_bottom).offset(AdaptedWidth(30));
        make.left.right.mas_equalTo(0);
        make.bottom.bottom.mas_equalTo(0);
    }];
    self.firstView.topLab.text = XLocalized(@"计算");
    [self.firstView.rightBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [MBProgressHUD showLoadTitile:@"" ToView:weakself.view];
        [weakself.foundServer getLeaseDappsCompletion:^(BOOL success, NSString * _Nonnull msg) {
            [MBProgressHUD hideHUDForView:weakself.view];
            if (success) {
                NSMutableArray*titles = [NSMutableArray array];
                [weakself.foundServer.leaseList enumerateObjectsUsingBlock:^(FoundRecommendModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    [titles addObject:obj.name];
                }];
                WeChatActionSheet*sheet =  [WeChatActionSheet showActionSheet:@"请选择" buttonTitles:titles];
                sheet.function = ^(WeChatActionSheet *actionSheet, NSInteger index) {
                    if (index != WECHATCANCELINDEX) {
                        [ScatterDappManager manager:weakself forDapp:[weakself.foundServer.leaseList objectOrNilAtIndex:index]];
                    }
                };
            }else{
                [weakself.view makeToast:msg];
            }
        }];
    }];
    
    self.secondView.topLab.text = XLocalized(@"网络");
    self.secondView.rightBtn.hidden = YES;


    self.middleView.topLab.text = XLocalized(@"内存");
    [self.middleView.rightBtn addTapBlock:^(UIButton * _Nonnull btn) {
        MemoryTradingViewController*vc = [MemoryTradingViewController new];
        vc.wallet = weakself.wallet;
        [weakself.navigationController pushViewController:vc animated:YES];
    }];
  
    ///提交交易
    self.chooseView.SureBlock = ^{
        [WalletTool checkPrivateInputPasswordWith:weakself.wallet complete:^(BOOL result,NSString * _Nonnull privateKey) {
            if (result) {
                weakself.eosService.toUser = weakself.chooseView.isSelf?weakself.wallet.wallet_name:weakself.chooseView.userTF.text;
                weakself.eosService.isMortgage = weakself.chooseView.isMortgage;
                NSString* stake_cpu_quantity = [NSString stringWithFormat:@"%@ %@",[NSString stringWithFormat:@"%.*lf",kSymbolLength_EOS,[weakself.chooseView.cpuTF.text.length?weakself.chooseView.cpuTF.text:@"0" doubleValue]],kSymbolName_EOS];
                NSString* stake_net_quantity = [NSString stringWithFormat:@"%@ %@",[NSString stringWithFormat:@"%.*lf",kSymbolLength_EOS,[weakself.chooseView.netTF.text.length?weakself.chooseView.netTF.text:@"0" doubleValue]],kSymbolName_EOS];
                weakself.eosService.stake_cpu_quantity = stake_cpu_quantity;
                weakself.eosService.stake_net_quantity = stake_net_quantity;
                weakself.eosService.account = kContractName_EOSIO;
                weakself.eosService.available_keys = @[VALIDATE_STRING(weakself.wallet.wallet_public_key)];
                weakself.eosService.actor = weakself.wallet.wallet_name;
                weakself.eosService.privateKey = privateKey;
                [MBProgressHUD showLoadTitile:@"" ToView:weakself.view];
                if (weakself.chooseView.type == ResourcesDetailsChooseTypeMortgage) {
                    weakself.eosService.action = ContractAction_DELEGATEBW;
                    [weakself.eosService mortgageResourcesComplete:^(BOOL success, NSString * _Nonnull errorMsg) {
                        [MBProgressHUD hideHUDForView:weakself.view];
                        [weakself.view makeToast:errorMsg];
                        if (success) {
                            [weakself getaccountInfo];
                        }
                        weakself.chooseView.cpuTF.text = @"";
                        weakself.chooseView.netTF.text = @"";
                        weakself.chooseView.userTF.text = @"";
                    }];
                }else{
                    weakself.eosService.action = ContractAction_UNDELEGATEBW;
                    [weakself.eosService redemptionResourcesComplete:^(BOOL success, NSString * _Nonnull errorMsg) {
                        [MBProgressHUD hideHUDForView:weakself.view];
                        [weakself.view makeToast:errorMsg];
                        if (success) {
                            [weakself getaccountInfo];
                        }
                        weakself.chooseView.cpuTF.text = @"";
                        weakself.chooseView.netTF.text = @"";
                        weakself.chooseView.userTF.text = @"";
                    }];
                }
              
            }
        }];
      
    };
    
    
    self.scrollContentView.mj_header = [LxHeader headerWithRefreshingBlock:^{
        [self getaccountInfo];
    }];
}

- (EOSService*)eosService{
    if (!_eosService) {
        _eosService = [EOSService new];
        _eosService.wallet = self.wallet;
    }
    return _eosService;
}

#pragma mark - getter
- (FoundServer*)foundServer{
    if (!_foundServer) {
        _foundServer = [FoundServer new];
    }
    return _foundServer;
}
@end


